<?php
namespace Huiyuan\Controller;

use Think\Controller;
/**
 * 绿地会员注册
 */
class IntegralController extends CommonController
{    
	 
	//报名，登陆
	public function index()
	{          
		echo $this->openid  = $this->openid();
		print_r(session());
		//会员
		$usr = M('t_huiyuan')->where(array('open_id'=>$this->openid))->find();
		if($usr){
			//call sand api
                                    sand_api_call();
                                    $score = getCredits($usr['card_no']);
                                    $usr['score'] = $score;
			$this->usr = $usr;
			$this->display('Yhjf');
		}else{
			$this->cityList = $this->cityList();
			$this->display();	
		}
		
	}

 	//验证登陆
	public function Regist(){

		$data = $_POST;
                        $post_data = json_decode($data['info'],true);
		// 验证码验证 
		if(!M("t_authcode")->where(array('tel'=>$post_data['HuiyuanTel'],'authcode'=>$post_data['authCode']))->find()){
			$this->ajaxReturn('5');
		}
		//sand 接口
	 
	}

	//短信验证码发送
	public function SendCode(){
		$tel  =  I('tel');
		if(preg_match("/1[3458]{1}\d{9}$/",$tel)){
			
			import('Vendor.Sms.sms');
			$sms = new \sms();	
			$mobile_code = phone_random(0,9);
			$content = "您的验证码是：" . $mobile_code . "。请不要把验证码泄露给其他人。";
			$result  = $sms->sendTo($tel,$content );
			$date = array('tel'=>$tel,'authcode'=>$mobile_code,'create_time'=>date("Y-m-d H:i:s"));
			if(2==$result['code']){
				M('t_authcode')->add($date);
				$this->ajaxReturn("1");
			}else{
				$this->ajaxReturn($result);
			}
		}else{
			$this->ajaxReturn('手机号码不正确');
		}
	}	   
		   
	//城市楼盘
	private function cityList(){
		$city = M("t_code_detail")->where(array('code_id'=>'10'))->order('id')->select();
		$tmp ='<option value="-1">请选择</option>';
		foreach($city  as $v){
			$tmp .= '<option value="'.$v['code_key'].'">'.$v['code_name'].'</option>';
		}
		return $tmp;
	}
	//城市楼盘详情
	public function GetCodeDetail(){
		$codeId =I('codeId');
		if($codeId)
			$project = M("t_code_detail")->where(array('code_id'=>$codeId))->select();
		$tmp ='';
		foreach($project  as $v){
			$tmp .= '<option value="'.$v['code_key'].'">'.$v['code_name'].'</option>';
		}
		echo ($tmp);
	}
	public function test(){
		$url = 'http://ldh.mo2.cn/huiyuan.php/Integral/index/GetCodeDetail?codeid=001';
		$w = file_get_contents($url);

		print_r($w);
	}

}